<?php

/**
 * MLEPP - ManiaLive Extending Plugin Pack
 *
 * -- MLEPP Plugin --
 * @name Chat Emotes
 * @date 30-06-2011
 * @version r851
 * @website mlepp.trackmania.nl
 * @package MLEPP
 *
 * @author Max "TheM" Klaversma <maxklaversma@gmail.com>
 *         Petri "reaby" Järvisalo <petri.jarvisalo@mbnet.fi>
 *         Guy "Knutselmaaster" Van Der Zel <knutselmaaster@gmail.com>
 * @copyright 2010 - 2011
 *
 * ---------------------------------------------------------------------
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * ---------------------------------------------------------------------
 * You are allowed to change things or use this in other projects, as
 * long as you leave the information at the top (name, date, version,
 * website, package, author, copyright) and publish the code under
 * the GNU General Public License version 3.
 * ---------------------------------------------------------------------
 */

namespace ManiaLivePlugins\MLEPP\ChatEmotes;

use ManiaLive\DedicatedApi\Connection;
use ManiaLive\Utilities\Console;
use ManiaLive\Data\Storage;
use ManiaLive\Config\Loader;
use ManiaLive\Event\Dispatcher;

use ManiaLivePlugins\MLEPP\Core\Core;
use ManiaLivePlugins\MLEPP\Core\Mlepp;

class ChatEmotes extends \ManiaLive\PluginHandler\Plugin {

	public static $bootme = array("chooses the life, bye all!", "has the illusion that he has got something better to do!", "takes the blue pill!", "exits, stage left!", "chooses to boot to the life!", "has seen the light. Oh the enlightenment!",
		"Beam me up Scotty!", "has left the building");
	public static $hi = array("Hi!", "Yo!", "Aloha!", "Hola!", "Hey!", "Hello!", "Hi to all!", "Yo Duudz!", "Aloha everybody?", "Hola!", "Ahoi sailors!", "Hey jude.. ehem.. all :)", "Hello strangers!", "O Hai, can I come in?", "Yop!", "Greetings Earthlings!");
	public static $hi2 = array("Hi", "Yo", "Hoi", "Aloha", "Hola", "Hey", "Hello", "Hola", "How are you doing", "Nice to see you here", "Yop");
	public static $bb = array("Bye Bye!", "Latorz!", "See ya later!", "Goodbye!", "Hasta la vista!", "Ciao!", "is out of here, bye!", "bye all!!");
	public static $bb2 = array("Bye Bye", "Latorz", "See ya later", "Goodbye", "Hasta la vista", "Ciao", "is out of here, bye", "hope to see you soon");
	public static $thx = array("Thanks!", "Thank you!", "Many thanks!", "Shows gratitude", "is grateful", "bows deep");
	public static $thx2 = array("Thanks", "Thank you", "Many thanks", "That is very kind of you", "How thoughtfull of you", "Great! I needed that");
	public static $lol = array("is rolling on the floor, laughing his *ss off", "Lo0o0ol", "is having a lot of laugh", "is laughing", "is laughing out loud", "xD", "Lulz", "That is just sooo funny!", "Hahahaha", "Hehehe");
	public static $lol2 = array("is rolling on the floor, laughing his *ss off because of", "Lo0o0ol", "is having a lot of laugh", "is laughing about", "is laughing out loud thanks to", "xD", "Lulz", "That is just sooo funny", "hahaha, you're killing me",
		"you're making me laugh");
	public static $brb = array("Be Right Back!", "Back in a sec!", "One moment, please...", "I'll be back!", "Hold on...", "Have to let you alone for a sec...");
	public static $brb2 = array("Be Right Back", "Back in a sec", "One moment, please", "I'll be back", "Hold on...", "Have to let you alone for a sec", "Please wait, i'll be right back");
	public static $afk = array("Away From Keyboard", "Wait,wait, the phone just rang", "Needs to press anykey on keyboard, but can't find it", "Where did my keyboard go?", "Letting my game spec itself for a moment",
		"I'll be speccing, but i'm not here so don't panic");
	public static $afk2 = array("Away From Keyboard", "Wait,wait, the phone just rang", "Needs to press anykey on keyboard, but can't find it", "Letting my game spec itself for a moment", "I'll be speccing, but i'm not here so don't panic");
	public static $gg = array("Congratulations!", "Good Game!", "Well Done!", "Great Game!");
	public static $gg2 = array("Congratulations", "Good Game", "Well Done", "Great Game");
	public static $nl = array("Nice one!", "Well driven, mate!", "Nice Line!", "How on earth you did that time?", "Damn. You are pro and i'm.. well i'm noob ;(", "Wo0o0o0t! You rule!", "You're a Pro!", "Now that is some great skills!", "Very impressing!",
		"O Master, please teach me!", "Where did you learn how to do that?");
	public static $nl2 = array("Nice one", "Well driven", "Nice Line", "How on earth you did that time", "Damn. You are pro and i'm.. well i'm noob ;( ", "Wo0o0o0t! You rule", "Have you ever thought of becoming Pro", "That was some skilled driving",
		"Very impressing", "Please teach me how to do that", "You're the master", "Can I have the address of your driving school");
	public static $bgm = array("Bad game for me!", "Ai, something went terribly wrong here!", "That wasn't me, it was my little brother playing...", "Did we begin yet?", "mumbles something about lag and bugs...", "You are great drivers, teach me please!",
		"is on the phone with a driving school!", "This is not my kind of track!", "That went sooo wrong!", "Just leave me alone now please :(", "Give....me....vitamins...", "That was not the way it supposed to go....");
	public static $bgm2 = array("Bad game for me", "Ai, something went terribly wrong here", "That wasn't me, it was my little brother playing...", "Did we begin yet", "You are a great driver, teach me please",
		"is on the phone with a driving school", "This is not my kind of track", "That went sooo wrong", "Just leave me alone now please", "Give....me....vitamins...");
	public static $sry = array("Sorry!", "Excuse me!", "I beg your pardon!");
	public static $sry2 = array("Sorry", "Excuse me", "I beg your pardon", "sends flowers to");
	public static $glhf = array("Good Luck & Have Fun!");
	public static $glhf2 = array("Good Luck & Have Fun");
	public static $wb = array("Welcome Back!");
	public static $wb2 = array("Welcome back");
	public static $omg = array("Oh My God!");
	public static $omg2 = array("Oh My God");
	public static $buzz = array("Wake up!", "Is anybody home?", "Yohooo, are you there?", "Echo Charly Delta, do you read me, please come in - over!", "This is Earth calling!", "Bzzzzzzzzzzz", "starts to get impatient!");
	public static $buzz2 = array("Wake up", "Are you there", "This is Earth calling", "Did i miss your /afk", "Are you still with me", "is calling", "starts to get impatient");
	public static $eat = array("is going to eat something", "I'm hungry, i need to go eat something!", "is going to take a bite!", "is grabbing something to snack!");
	public static $eat2 = array("I'm going to eat something", "Be right back, i grab something to eat");
	public static $drink = array("is going to drink something", "I'm thirsty, i need to go drink something!", "is going to take a drink!", "is grabbing something to drink!");
	public static $drink2 = array("I'm going to drink something", "Wait a sec, i'm taking something to drink");
	public static $rant = array("?#@*&%!", "\$f00\$oAaaaarrrghhhh!", "omg!", "Grrrrrr", "Noooooooo!", "Son of a bean dip, mother frito!", "oh, poo!", "***Explicit language***", "I've had a perfectly wonderful day. But this wasn't it.", "A Life? Cool! Where can I download one of those from?",
		"I don't suffer from insanity. I enjoy every minute of it.", "I feel like I'm diagonally parked in a parallel universe.", "Okay, who put a stop payment on my reality check?");
	public static $rant2 = array("May you never get more than one sheet of toilet paper at a time", "You can't fight ya way out of a paper bag", "If at first you don't succeed, give up", "Try, try and try again until you are ready for bed", "May the force be without you",
		"I'm busy now. Can I ignore you some other time? ", "It is only too easy to catch people's attention by doing something worse than anyone else has dared to do it before", "You are so computer illiterate, you shake your laptop to get the cookies out",
		"You're not important - you're just an NPC", "Wow, you're so slow, is your ping at 999", "Keep talking, someday you'll say something intelligent", "If you had another brain, it would be lonely", "If your brain was chocolate it wouldn't fill an M&M",
		"Genius does what it must, talent does what it can, and you had best do what you're told", "I didn't say it was your fault. I said I was going to blame you", "It IS as bad as you think, and they ARE out to get you", "Nothing is foolproof to a talented fool.",
		"It may be that your sole purpose in life is simply to serve as a warning to others");
	public static $ragequit = array("Ragequits!", "Has used the ejecting seat to get out of a tight situation!", "Out of my mind. Back in five minutes.", "Couldn't stand it anymore!", "Banged his head too hard on his keyboard!", "Quits, to take a valium!", "\$f00\$oRoaaarrrrrr!!!");
    private $mlepp;
    private $counters = array();
	private $tick = 0;
    /**
     * onInit()
     * Function called on initialisation of ManiaLive.
     *
     * @return void
     */

	function onInit() {
		// this needs to be set in the init section
		$this->setPublicMethod('getVersion');
		$this->setVersion(851);
		//ML Repository
		if(Core::RepositoryId != null) {
			$this->setRepositoryId(Core::RepositoryId);
			$this->setRepositoryVersion(Core::RepositoryVersion);
		}
		//Oliverde8 Menu
		if($this->isPluginLoaded('oliverde8\HudMenu')) {
			Dispatcher::register(\ManiaLivePlugins\oliverde8\HudMenu\onOliverde8HudMenuReady::getClass(), $this);
		}

	}

    /**
     * onLoad()
     * Function called on loading of ManiaLive.
     *
     * @return void
     */

	function onLoad() {
		Console::println('[' . date('H:i:s') . '] [MLEPP] Plugin: ChatEmotes r' . $this->getVersion() . ' by TheM, reaby & Knutselmaaster.');
		//$this->enableDedicatedEvents();
		$commands = array("bb", "bye", "hi", "hello", "thx", "ty", "lol", "brb", "afk", "gg", "nl", "bgm", "sry", "sorry", "glhf", "wb", "omg", "buzz", "eat", "drink", "rant", "ragequit", "bootme");
		$help = "performs a chatemote.";
		foreach($commands as $command) {
			$cmd = $this->registerChatCommand($command, $command, -1, true);
			$cmd->help = $help;

		}
		$oneliners = array("joke", "fact", "proverb", "quote");

		foreach($oneliners as $command) {
			$cmd = $this->registerChatCommand($command, $command, 0, true);
			$cmd->help = $help;
		}
		$this->enableDedicatedEvents();
		$this->enableTickerEvent();
		$this->mlepp = Mlepp::getInstance();
                }

	/**
	 * onOliverde8HudMenuReady()
     * Function used for adding buttons to Olivers Hud Menu.
	 *
	 * @param mixed $menu
	 * @return void
	 */
	public function onOliverde8HudMenuReady($menu) {
		$parent = $menu->findButton(array("Menu", "Basic Commands"));

		if(!$parent) {
			$button["style"] = "Icons64x64_1";
			$button["substyle"] = "GenericButton";
			$parent = $menu->addButton("Menu", "Basic Commands", $button);
		}
		$button["plugin"] = $this;

		$button["style"] = "Icons64x64_1";
		$button["substyle"] = "StateSuggested";
		$parent = $menu->addButton($parent, "Chat Emotes", $button);

		$commands = array("bb", "bye", "hi", "hello", "thx", "ty", "lol", "brb", "afk", "gg", "nl", "bgm", "sry", "sorry", "glhf", "wb", "omg", "buzz", "eat", "drink", "rant", "ragequit", "bootme");
		foreach($commands as $command) {
			$button["function"] = $command;
			$new['params'] = "null";
			$menu->addButton($parent, $command, $button);
		}
	}

	function onUnload() {
			parent::onUnload();
	}

	function onTick() {
		if ($this->tick >= 5)
		{
			$this->tick = 0;
			foreach($this->counters as $login => $data) {
			if ($data > 0) $this->counters[$login]--;
			}
		}
		$this->tick++;
	}

	function onPlayerDisconnect($login) {
		if (isset($this->counters[$login])) unset($this->counters[$login]);
	}

	/**
	 * bootme()
     * Function providing the /bootme command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function bootme() {
		$args = func_get_args();
		$login = array_shift($args);
		$param = implode(" ",$args);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /bootme command.');
		$player = $this->storage->getPlayerObject($login);
		$nick = $player->nickName;
		$message = (string) self::$bootme[rand(0, count(self::$bootme) - 1)];
		$this->mlepp->sendChat($nick . ' $z$s %emote%'. $message);
		$this->connection->kick($player);
	}

	/**
	 * ragequit()
     * Function providing the /ragequit command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function ragequit() {
		$args = func_get_args();
		$login = array_shift($args);
		$param = implode(" ",$args);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /ragequit command.');
		$player = $this->storage->getPlayerObject($login);
		$nick = $player->nickName;
		$message = (string) self::$ragequit[rand(0, count(self::$ragequit) - 1)];
		$this->mlepp->sendChat($nick . ' $z$s %emote%'. $message);
		$this->connection->kick($player);
	}

	/**
	 * hi()
     * Function providing the /hi command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function hi() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$hi, self::$hi2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /hi command.');
	}

	/**
	 * hello()
     * Function providing the /hello command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function hello() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$hi, self::$hi2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /hello command.');
	}

	/**
	 * thx()
     * Function providing the /thx command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function thx() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$thx, self::$thx2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /thx command.');
	}

	/**
	 * ty()
     * Function providing the /ty command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function ty() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args,self::$thx, self::$thx2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /ty command.');
	}

	/**
	 * bb()
     * Function providing the /bb command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function bb() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$bb, self::$bb2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /bb command.');
	}

	/**
	 * bye()
     * Function providing the /bye command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function bye() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$bb, self::$bb2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /bye command.');
	}

	/**
	 * lol()
     * Function providing the /lol command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function lol() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$lol, self::$lol2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /lol command.');
	}

	/**
	 * brb()
     * Function providing the /brb command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function brb() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args,self::$brb, self::$brb2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /brb command.');
	}

	/**
	 * afk()
     * Function providing the /afk command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function afk() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$afk, self::$afk2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /afk command.');
	}

	/**
	 * gg()
     * Function providing the /gg command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function gg() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$gg, self::$gg2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /gg command.');
	}

	/**
	 * nl()
     * Function providing the /nl command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function nl() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$nl, self::$nl2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /nl command.');
	}

	/**
	 * bgm()
     * Function providing the /bgm command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function bgm() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$bgm, self::$bgm2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /bgm command.');
	}

	/**
	 * sry()
     * Function providing the /sry command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function sry() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$sry, self::$sry2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /sry command.');
	}

	/**
	 * sorry()
     * Function providing the /sorry command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function sorry() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$sry, self::$sry2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /sorry command.');
	}

	/**
	 * glhf()
     * Function providing the /glhf command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function glhf() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$glhf, self::$glhf2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /glhf command.');
	}

	/**
	 * wb()
     * Function providing the /wb command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function wb() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$wb, self::$wb2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /wb command.');
	}

	/**
	 * omg()
     * Function providing the /omg command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function omg() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$omg, self::$omg2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /omg command.');
	}

	/**
	 * buzz()
     * Function providing the /buzz command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function buzz() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$buzz, self::$buzz2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /buzz command.');
	}

	/**
	 * eat()
     * Function providing the /eat command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function eat() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$eat, self::$eat2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /eat command.');
	}

	/**
	 * drink()
     * Function providing the /drink command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function drink() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$drink, self::$drink2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /drink command.');
	}

	/**
	 * rant()
     * Function providing the /rant command.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @return void
	 */

	function rant() {
		$args = func_get_args();
		$login = array_shift($args);
		$this->helper($login, $args, self::$rant, self::$rant2);
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /rant command.');
	}

	/**
	 * joke()
     * Function providing the /joke command.
	 *
	 * @param mixed $login
	 * @return void
	 */

	function joke($login) {
		$this->oneLiner($login, "jokes");
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /joke command.');
	}

	/**
	 * fact()
     * Function providing the /fact command.
	 *
	 * @param mixed $login
	 * @return void
	 */

	function fact($login) {
		$this->oneLiner($login, "facts");
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /fact command.');
	}

	/**
	 * proverb()
     * Function providing the /proverb command.
	 *
	 * @param mixed $login
	 * @return void
	 */

	function proverb($login) {
		$this->oneLiner($login, "proverbs");
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /proverb command.');
	}

	/**
	 * quote()
     * Function providing the /quote command.
	 *
	 * @param mixed $login
	 * @return void
	 */

	function quote($login) {
		$this->oneLiner($login, "quotes");
        Console::println('['.date('H:i:s').'] [MLEPP] [ChatEmotes] ['.$login.'] Player used /quote command.');
	}

	/**
	 * helper()
     * Helper function, does the hard stuff for outputting text.
	 *
	 * @param mixed $login
	 * @param mixed $param
	 * @param mixed $text
	 * @param mixed $source1
	 * @param mixed $source2
	 * @return void
	 */

	function helper($login, $args, &$source1, &$source2) {

		if (!isset($this->counters[$login]) ) $this->counters[$login] = 1;
		if (isset($this->counters[$login]) && $this->counters[$login] >= 3) return;
		if (isset($this->counters[$login])) $this->counters[$login]++;
		//print		$this->counters[$login];
		$player = $this->storage->getPlayerObject($login);
		$message = (string) $source1[rand(0, count($source1) - 1)];
		$message2 = (string) $source2[rand(0, count($source2) - 1)];

		if(isset($args[0])) {

			if( ($nick = $this->getPlayerNick($args[0])) == "") {
			$text = implode(" ",$args);
				$this->mlepp->sendChat($player->nickName . '$z$s  %emote%'. $message2 . " %emote%". $text);
			} else {
				array_shift($args);
				$text = implode(" ",$args);
				$this->mlepp->sendChat($player->nickName . '$z$s %emote%'. $message2 . ", " . $nick . " %emote%". $text);
			}
		} else {
			$this->mlepp->sendChat($player->nickName . '$z$s  %emote%'. $message);
		}
	}

	/**
	 * oneLiner()
     * Function used for outputting one-liners.
	 *
	 * @param mixed $login
	 * @param mixed $file
	 * @return void
	 */

	function oneLiner($login, $file) {
		$data = file_get_contents('libraries/ManiaLivePlugins/MLEPP/ChatEmotes/Texts/' . $file . '.txt');
		$lines = explode("\n", $data);
		$message = (string) $lines[rand(0, count($lines) - 1)];
		$player = $this->storage->getPlayerObject($login);
		$this->mlepp->sendChat($player->nickName . '$z$s  %emote%' . trim($message));
	}


	/**
	 * getPlayerNick()
     * Function used for getting someones nickname.
	 *
	 * @param mixed $login
	 * @return
	 */

	function getPlayerNick($login) {
		if(isset($this->storage->players[$login])) {
			$player = $this->storage->getPlayerObject($login);
			return $player->nickName;
		} else {
			if(isset($this->storage->spectators[$login])) {
				$player = $this->storage->getPlayerObject($login);
				return $player->nickName;
			} else {
				return "";
            }
		}
	}
}
?>